#!/bin/bash
#pxe安装脚本


#变量定义
pxe_ip=192.168.137.22
#pxe_ip=`ip addr|grep inet|grep brd|awk -F ' ' '{print substr($2,1,15)}'`
#pxe_ip=`ip addr | grep 'inet'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print substr($2,1,15)}'`
HTTP_PATH="/var/www/html/"
DHCP_PATH="/etc/dhcp/"
TFTP_PATH="/etc/xinetd/tftp"
#下载必要软件
yum install  tftp-server vim dhcp syslinux system-config-kickstart vsftpd xinetd -y

#配置dhcp
cp dhcpd.conf /etc/dhcp/

#配置tftp
tftp=`cat /etc/xinetd.d/tftp | grep 'disable                 = no'`
if [ "$tftp" == "" ];then
	sed -i '14s/yes/no/g' /etc/xinetd.d/tftp
fi


#配置ftp
mount /opt/CentOS-7-x86_64-Minimal-1708.iso /var/ftp/pub

#配置ks.cfg文件
cp ks.cfg /var/ftp/

#tftp目录文件准备
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
if [ ! -d /var/lib/tftpboot/pxelinux.cfg ];then 
	mkdir /var/lib/tftpboot/pxelinux.cfg
fi

cp /var/ftp/pub/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/
cp /var/ftp/pub/isolinux/{vesamenu.c32,boot.msg,splash.png} /var/lib/tftpboot/

#cp default文件
cp default /var/lib/tftpboot/pxelinux.cfg/

#启动服务器
iptables -F
systemctl start dhcpd
systemctl start xinetd
systemctl start tftp
systemctl start tftp.socket
systemctl start vsftpd
systemctl enable httpd
systemctl enable dhcpd
systemctl enable xinetd
systemctl enable tftp
systemctl enable tftp.socket
systemctl enable vsftpd
